
var express = require('express');


var app = express();
app.use(express.static('public'));


var fs = require("fs");
var weatherStr = fs.readFileSync("./weather.json", "utf-8");
var weather = JSON.parse(weatherStr);

var wr = weather.results[0];





app.set('view engine', 'ejs');


var current = wr.weather_data[0].date.substring(wr.weather_data[0].date.indexOf('：'));
current = current.replace(')','');
console.log(current);


var PM25=wr.pm25


app.get('/', function(req, res){
    res.render('list', {wr,current, p25:getPM25(PM25) });
});





function getPM25(value){
    var str = '';
    if (value < 35) {
        str = '优';
    }else if (value < 75) {
        str = '良';
    }else if (value < 115) {
        str = '轻度污染';
    }else if (value < 150) {
        str = '中度污染';
    }else if (value < 250) {
        str = '重度污染';
    }else  {
        str = '严重污染';
    }

    return str;
}

app.listen(5555, function() {
    console.log("服务器启动...");
  });
  